package com.cinorecycle.printqrcode.entity.result;

import com.cinorecycle.printqrcode.constant.CommonConstant;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
// @Api(value = "返回值通用类型")
public class ResultVo<T> {

    // @ApiModelProperty(value = "0：请求正常、-1：请求异常 、21315：需要重新获取jwtToken")
    private Integer code;

    // @ApiModelProperty(value = "成功或失败提示")
    private String msg;

    // @ApiModelProperty(value = "结果数据集")
    private T data;

    // @ApiModelProperty(value = "数量")
    private Long count;

    public ResultVo() {
    }

    public ResultVo(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResultVo(Integer code, String msg, T data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    public static <T> ResultVo<T> ok() {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_OK);
        resultVo.setMsg(CommonConstant.MSG_OK);
        return resultVo;
    }

    public static <T> ResultVo<T> ok(String msg) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_OK);
        resultVo.setMsg(msg);
        return resultVo;
    }

    public static <T> ResultVo<T> ok(String msg, T t) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_OK);
        resultVo.setMsg(msg);
        resultVo.setData(t);
        return resultVo;
    }

    public static <T> ResultVo<T> ok(T t) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_OK);
        resultVo.setMsg(CommonConstant.MSG_OK);
        resultVo.setData(t);
        return resultVo;
    }


    public static <T> ResultVo<T> ok(String msg, Long count, T t) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_OK);
        resultVo.setMsg(msg);
        resultVo.setData(t);
        resultVo.setCount(count);
        return resultVo;
    }

    public static <T> ResultVo<T> ok(Long count, T t) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_OK);
        resultVo.setMsg(CommonConstant.MSG_OK);
        resultVo.setData(t);
        resultVo.setCount(count);
        return resultVo;
    }

    public static <T> ResultVo<T> fail() {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_FAIL);
        resultVo.setMsg(CommonConstant.MSG_FAIL);
        return resultVo;
    }

    public static <T> ResultVo<T> fail(int code) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(code);
        resultVo.setMsg(CommonConstant.MSG_FAIL);
        return resultVo;
    }

    public static <T> ResultVo<T> fail(String msg) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(CommonConstant.CODE_FAIL);
        resultVo.setMsg(msg);
        return resultVo;
    }

    public static <T> ResultVo<T> fail(int code, String msg) {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(code);
        resultVo.setMsg(msg);
        return resultVo;
    }

    /**
     * 判断是否成功
     *
     * @return
     */
    public boolean isOk() {
        if (this.code == 0)
            return true;
        return false;
    }

    /**
     * 判断是否失败
     *
     * @return
     */
    public boolean isFail() {
        if (this.code != 0)
            return true;
        return false;
    }
}
